//
//  TTCoreGeometry.m
//  Tint
//
//  Created by Kevin Wu on 2/22/12.
//  Copyright (c) 2012 Telligenty. All rights reserved.
//

#import "TTCoreGeometry.h"



#pragma mark - Angle

CGFloat TTDegreesToRadians(CGFloat degrees) {
    return (M_PI * degrees / 180.0);
}

CGFloat TTRadiansToDegrees(CGFloat radians) {
    return (radians * 180.0 / M_PI);
}



#pragma mark - Point

CGPoint TTPointMake(CGFloat x, CGFloat y) {
    return CGPointMake(round(x), round(y));
}
CGPoint TTPointZero(void) {
    return CGPointZero;
}
CGPoint TTPointSame(CGFloat x) {
    return CGPointMake(round(x), round(x));
}

CGPoint TTPointSetX(CGPoint point, CGFloat x) {
    return CGPointMake(round(x), point.y);
}
CGPoint TTPointSetY(CGPoint point, CGFloat y) {
    return CGPointMake(point.x, round(y));
}

BOOL TTIsPointEqualToPoint(CGPoint point1, CGPoint point2) {
    return CGPointEqualToPoint(point1, point2);
}



#pragma mark - Size

CGSize TTSizeMake(CGFloat width, CGFloat height) {
    return CGSizeMake(round(width), round(height));
}
CGSize TTSizeZero(void) {
    return CGSizeZero;
}
CGSize TTSizeSquare(CGFloat width) {
    return CGSizeMake(round(width), round(width));
}

CGSize TTSizeSetWidth(CGSize size, CGFloat width) {
    return CGSizeMake(round(width), size.height);
}
CGSize TTSizeSetHeight(CGSize size, CGFloat height) {
    return CGSizeMake(size.width, round(height));
}

CGSize TTSizeToFitSize(CGSize bounds, CGSize size) {
    CGFloat factor1 = bounds.width/size.width;
    CGFloat factor2 = bounds.height/size.height;
    CGFloat factor = MIN(factor1, factor2);
    return CGSizeMake(round(size.width * factor), round(size.height * factor));
}

BOOL TTIsSizeEqualToSize(CGSize size1, CGSize size2) {
    return CGSizeEqualToSize(size1, size2);
}




#pragma mark - Rect

CGRect TTRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height) {
    return CGRectMake(round(x), round(y), round(width), round(height));
}
CGRect TTRectZero(void) {
    return CGRectZero;
}
CGRect TTRectNull(void) {
    return CGRectNull;
}
CGRect TTRectInfinite(void) {
    return CGRectInfinite;
}
CGRect TTRectWithSize(CGSize size) {
    return CGRectMake(0.0, 0.0, size.width, size.height);
}
CGRect TTRectWithWH(CGFloat width, CGFloat height) {
    return CGRectMake(0.0, 0.0, round(width), round(height));
}
CGRect TTRectWithW(CGFloat width) {
    return CGRectMake(0.0, 0.0, round(width), round(width));
}

CGRect TTRectSetX(CGRect rect, CGFloat x) {
    return CGRectMake(round(x), rect.origin.y, rect.size.width, rect.size.height);
}
CGRect TTRectSetY(CGRect rect, CGFloat y) {
    return CGRectMake(rect.origin.x, round(y), rect.size.width, rect.size.height);
}
CGRect TTRectSetWidth(CGRect rect, CGFloat width) {
    return CGRectMake(rect.origin.x, rect.origin.y, round(width), rect.size.height);
}
CGRect TTRectSetHeight(CGRect rect, CGFloat height) {
    return CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, round(height));
}
CGRect TTRectSetOrigin(CGRect rect, CGPoint point) {
    return CGRectMake(point.x, point.y, rect.size.width, rect.size.height);
}
CGRect TTRectSetSize(CGRect rect, CGSize size) {
    return CGRectMake(rect.origin.x, rect.origin.y, size.width, size.height);
}

CGFloat TTRectGetWidth(CGRect rect) {
    return CGRectGetWidth(rect);
}
CGFloat TTRectGetHeight(CGRect rect) {
    return CGRectGetHeight(rect);
}
CGFloat TTRectGetLeftX(CGRect rect) {
    return CGRectGetMinX(rect);
}
CGFloat TTRectGetCenterX(CGRect rect) {
    return CGRectGetMidX(rect);
}
CGFloat TTRectGetRightX(CGRect rect) {
    return CGRectGetMaxX(rect);
}
CGFloat TTRectGetTopY(CGRect rect) {
    return CGRectGetMinY(rect);
}
CGFloat TTRectGetCenterY(CGRect rect) {
    return CGRectGetMinY(rect);
}
CGFloat TTRectGetBottomY(CGRect rect) {
    return CGRectGetMaxY(rect);
}

CGRect TTRectContract(CGRect rect, CGFloat dx, CGFloat dy) {
    return CGRectMake(rect.origin.x, rect.origin.y, rect.size.width-dx, rect.size.height-dy);
}
CGRect TTRectShift(CGRect rect, CGFloat dx, CGFloat dy) {
    return CGRectMake(rect.origin.x+dx, rect.origin.y+dy, rect.size.width-dx, rect.size.height-dy);
}
CGRect TTRectClearCoords(CGRect rect) {
    return CGRectMake(0.0, 0.0, rect.size.width, rect.size.height);
}
CGRect TTRectStandardize(CGRect rect) {
    return CGRectStandardize(rect);
}
CGRect TTRectInset(CGRect rect, CGFloat dx, CGFloat dy) {
    return CGRectInset(rect, dx, dy);
}
CGRect TTRectIntegral(CGRect rect) {
    return CGRectIntegral(rect);
}
CGRect TTRectUnion(CGRect rect1, CGRect rect2) {
    return CGRectUnion(rect1, rect2);
}
CGRect TTRectIntersection(CGRect rect1, CGRect rect2) {
    return CGRectIntersection(rect1, rect2);
}
CGRect TTRectOffset(CGRect rect, CGFloat dx, CGFloat dy) {
    return CGRectOffset(rect, dx, dy);
}

void TTRectDivide(CGRect rect, CGRect *slice, CGRect *remainder, CGFloat amount, CGRectEdge edge) {
    CGRectDivide(rect, slice, remainder, amount, edge);
}

BOOL TTIsRectEqualToRect(CGRect rect1, CGRect rect2) {
    return CGRectEqualToRect(rect1, rect2);
}
BOOL TTIsRectEmpty(CGRect rect) {
    return CGRectIsEmpty(rect);
}
BOOL TTIsRectNull(CGRect rect) {
    return CGRectIsNull(rect);
}
BOOL TTIsRectInfinite(CGRect rect) {
    return CGRectIsInfinite(rect);
}
BOOL TTIsRectContainsPoint(CGRect rect, CGPoint point) {
    return CGRectContainsPoint(rect, point);
}
BOOL TTIsRectContainsRect(CGRect rect1, CGRect rect2) {
    return CGRectContainsRect(rect1, rect2);
}
BOOL TTIsRectIntersectsRect(CGRect rect1, CGRect rect2) {
    return CGRectIntersectsRect(rect1, rect2);
}
